package com.jerry.base.java8.lambda;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;
import java.util.function.Supplier;

/**
 * 函数式接口
 *
 * @author Jerry
 * @since 2024/7/18 20:33
 */
public class CategoryTest {

    static class Student {
        private String name;
        private int age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }

    public static void main(String[] args) {
        IntPredicate inter1 = (int a) -> (a & 1) == 0;
        IntPredicate inter2 = (int a) -> BigInteger.valueOf(a).isProbablePrime(100);
        Inter2 inter3 = (int a, int b, int c) -> a + b + c;
        IntBinaryOperator inter4 = (int a, int b) -> a - b;
        IntBinaryOperator inter5 = (int a, int b) -> a * b;
        Supplier<Student> inter6 = Student::new;
        Supplier<List<Student>> inter7 = ArrayList::new;
        Function<Student, String> inter8 = Student::getName;
        Function<Student, Integer> inter9 = Student::getAge;
    }

    @FunctionalInterface
    interface Inter1 {
        boolean function(int a);
    }

    @FunctionalInterface
    interface Inter2 {
        int function(int a, int b, int c);
    }

    @FunctionalInterface
    interface Inter3 {
        int function(int a, int b);
    }

    @FunctionalInterface
    interface Inter4<T> {
        T function();
    }

    @FunctionalInterface
    interface Inter5<I, O> {
        O function(I in);
    }
}
